package com.qingcheng.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.qingcheng.dao.CategoryReportMapper;
import com.qingcheng.pojo.report.CategoryReport;
import com.qingcheng.service.order.CategoryReportService;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @author 岳剑飞
 * @Company http://www.ithiema.com
 */
@Service(interfaceClass = CategoryReportService.class)
public class CategoryReportServiceImpl implements CategoryReportService {

    @Autowired
    private CategoryReportMapper categoryReportMapper;
    /**
     * 商品类目按日期统计(订单表关联查询)
     * @param date
     * @return
     */
    @Override
    public List<CategoryReport> categoryReport(LocalDate date) {

        return categoryReportMapper.categoryReport(date);
    }

    /**
     * 定时任务 - 生成统计数据
     */
    @Override
    public void createData() {
        //LocalDate localDate = LocalDate.now().minusDays(1); //生成前一天的时间
        LocalDate localDate = LocalDate.now(); //生成今天的时间

        List<CategoryReport> categoryReports = categoryReportMapper.categoryReport(localDate);
        for (CategoryReport categoryReport : categoryReports) {
            categoryReportMapper.insert(categoryReport);
        }
    }
    /**
     * 一级类目统计
     * @param beginDate
     * @param endDate
     * @return
     */
    @Override
    public List<Map> category1Count(String beginDate, String endDate) {
        return categoryReportMapper.category1Count(beginDate,endDate);
    }
}
